using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PharmacyDataInterf;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class PatientAllergyController : Controller
    {
		private readonly IDrugRepository drugRepository;
		private readonly IPatientAllergyGroupRepository patientallergygroupRepository;
		private readonly IPatientAllergyRepository patientallergyRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PatientAllergyController()// : this(new DrugRepository(), new PatientAllergyGroupRepository(), new PatientAllergyRepository())
        {
            this.drugRepository = Registry.RepositoryFactory.GetDrugRepository();
            this.patientallergygroupRepository = Registry.RepositoryFactory.GetPatientAllergyGroupRepository();
            this.patientallergyRepository = Registry.RepositoryFactory.GetPatientAllergyRepository();
        }

        public PatientAllergyController(IDrugRepository drugRepository, IPatientAllergyGroupRepository patientallergygroupRepository, IPatientAllergyRepository patientallergyRepository)
        {
			this.drugRepository = drugRepository;
			this.patientallergygroupRepository = patientallergygroupRepository;
			this.patientallergyRepository = patientallergyRepository;
        }

        //
        // GET: /PatientAllergy/

        public ViewResult Index()
        {
            return View(patientallergyRepository.All);//Including(patientallergy => patientallergy.Drug, patientallergy => patientallergy.Group));
        }

        //
        // GET: /PatientAllergy/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(patientallergyRepository.Find(id));
        }

        //
        // GET: /PatientAllergy/Create

        public ActionResult Create()
        {
			ViewBag.PossibleDrugs = drugRepository.All;
			ViewBag.PossibleGroups = patientallergygroupRepository.All;
            return View();
        } 

        //
        // POST: /PatientAllergy/Create

        [HttpPost]
        public ActionResult Create(PatientAllergy patientallergy)
        {
            if (ModelState.IsValid) {
                patientallergyRepository.Create(patientallergy);
                patientallergyRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleDrugs = drugRepository.All;
				ViewBag.PossibleGroups = patientallergygroupRepository.All;
				return View();
			}
        }
        
        //
        // GET: /PatientAllergy/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleDrugs = drugRepository.All;
			ViewBag.PossibleGroups = patientallergygroupRepository.All;
             return View(patientallergyRepository.Find(id));
        }

        //
        // POST: /PatientAllergy/Edit/5

        [HttpPost]
        public ActionResult Edit(PatientAllergy patientallergy)
        {
            if (ModelState.IsValid) {
                patientallergyRepository.Update(patientallergy);
                patientallergyRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleDrugs = drugRepository.All;
				ViewBag.PossibleGroups = patientallergygroupRepository.All;
				return View();
			}
        }

        //
        // GET: /PatientAllergy/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(patientallergyRepository.Find(id));
        }

        //
        // POST: /PatientAllergy/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var pa = patientallergyRepository.Find(id);
            patientallergyRepository.Delete(pa);
            patientallergyRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

